/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bookingtickets;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author alexxxey
 */
@Entity
@Table(name = "TICKETS")
@XmlRootElement
@NamedQueries(
{
    @NamedQuery(name = "Ticket.findAll", query = "SELECT t FROM Ticket t"),
    @NamedQuery(name = "Ticket.findByTripid", query = "SELECT t FROM Ticket t WHERE t.ticketPK.tripid = :tripid"),
    @NamedQuery(name = "Ticket.findByPlace", query = "SELECT t FROM Ticket t WHERE t.ticketPK.place = :place"),
    @NamedQuery(name = "Ticket.findByPasport", query = "SELECT t FROM Ticket t WHERE t.pasport = :pasport"),
    @NamedQuery(name = "Ticket.findByFirstname", query = "SELECT t FROM Ticket t WHERE t.firstname = :firstname"),
    @NamedQuery(name = "Ticket.findByLastname", query = "SELECT t FROM Ticket t WHERE t.lastname = :lastname"),
    
    @NamedQuery(name = "Ticket.findByTripAndPalce", query = "SELECT t FROM Ticket t WHERE t.ticketPK.tripid = :tripid"
        + " AND t.ticketPK.place = :place")
})
public class Ticket implements Serializable
{
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TicketPK ticketPK;
    @Column(name = "PASPORT")
    private Integer pasport;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 32)
    @Column(name = "FIRSTNAME")
    private String firstname;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 32)
    @Column(name = "LASTNAME")
    private String lastname;
    @JoinColumn(name = "TRIPID", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Trip trip;

    public Ticket()
    {
    }

    public Ticket(TicketPK ticketPK)
    {
        this.ticketPK = ticketPK;
    }

    public Ticket(TicketPK ticketPK, String firstname, String lastname)
    {
        this.ticketPK = ticketPK;
        this.firstname = firstname;
        this.lastname = lastname;
    }

    public Ticket(int tripid, int place)
    {
        this.ticketPK = new TicketPK(tripid, place);
    }

    public TicketPK getTicketPK()
    {
        return ticketPK;
    }

    public void setTicketPK(TicketPK ticketPK)
    {
        this.ticketPK = ticketPK;
    }

    public Integer getPasport()
    {
        return pasport;
    }

    public void setPasport(Integer pasport)
    {
        this.pasport = pasport;
    }

    public String getFirstname()
    {
        return firstname;
    }

    public void setFirstname(String firstname)
    {
        this.firstname = firstname;
    }

    public String getLastname()
    {
        return lastname;
    }

    public void setLastname(String lastname)
    {
        this.lastname = lastname;
    }

    public Trip getTrip()
    {
        return trip;
    }

    public void setTrip(Trip trip)
    {
        this.trip = trip;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (ticketPK != null ? ticketPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Ticket))
        {
            return false;
        }
        Ticket other = (Ticket) object;
        if ((this.ticketPK == null && other.ticketPK != null) || (this.ticketPK != null && !this.ticketPK.equals(other.ticketPK)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "bookingtickets.Ticket[ ticketPK=" + ticketPK + " ]";
    }
    
}
